package com.xbongbong.saas.toolbox.util;

import com.xbongbong.saas.enums.ListGroupEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.sys.enums.UserConfigEnum;

import java.util.Objects;

/**
 * @author 吴峰
 * @date 2021/12/16 20:29
 */
public class UserConfigUtil {

    public static String getKey(Integer subBusinessType,Long appId,Long formId) {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(subBusinessType);
        switch (xbbRefTypeEnum){
            case STOCK_SEARCH:
            case WARNING_SEARCH:
            case GUARANTEE_SEARCH:
            case WAIT_PURCHASE:
            case WAIT_PRODUCE:
            case WAIT_OUTSTOCK:
            case WAIT_INSTOCK_PURCHASE:
                return "";
            default:
                return appId + "_" + formId;
        }
    }

    public static String getDefaultSortConfigPrefix(Integer businessType, Integer subBusinessType, Long groupId) {
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(subBusinessType);
        switch (xbbRefTypeEnum){
            case STOCK_SEARCH:
                if (Objects.isNull(groupId) ){
                    return UserConfigEnum.STOCK_DEFAULT_SORT_FIELD.getAlias();
                } else if (Objects.equals(groupId.intValue(), ListGroupEnum.WARNING_SEARCH.getCode())){
                    return UserConfigEnum.WARN_DEFAULT_SORT_FIELD.getAlias();
                }else if (Objects.equals(groupId.intValue(),ListGroupEnum.GUARANTEE_SEARCH.getCode())){
                    return UserConfigEnum.GUARANTEE_PERIOD_DEFAULT_SORT_FIELD.getAlias();
                }
                return UserConfigEnum.STOCK_DEFAULT_SORT_FIELD.getAlias();
            case GUARANTEE_SEARCH:
                return UserConfigEnum.GUARANTEE_PERIOD_DEFAULT_SORT_FIELD.getAlias();
            case WARNING_SEARCH:
                return UserConfigEnum.WARN_DEFAULT_SORT_FIELD.getAlias();
            case WAIT_PURCHASE:
                if (Objects.equals(businessType,XbbRefTypeEnum.CONTRACT.getCode())){
                    return "waitPurchaseContractSortField";
                }else {
                    return "waitPurchaseProductSortField";
                }
            case WAIT_PRODUCE:
                if (Objects.equals(businessType,XbbRefTypeEnum.CONTRACT.getCode())){
                    return "waitProduceContractSortField";
                }else {
                    return "waitProduceProductSortField";
                }
            case WAIT_OUTSTOCK:
                if (Objects.equals(businessType,XbbRefTypeEnum.CONTRACT.getCode())){
                    return "waitOutstockContractSortField";
                }else {
                    return "waitOutstockProductSortField";
                }
            case WAIT_INSTOCK_PURCHASE:
                if (Objects.equals(businessType,XbbRefTypeEnum.PURCHASE.getCode())){
                    return "waitInstockPurchaseSortField";
                }else if (Objects.equals(businessType,XbbRefTypeEnum.PRODUCT.getCode())){
                    return "waitInstockProductSortField";
                }
            default:
                return UserConfigEnum.DEFAULT_SORT_FIELD.getAlias();
        }
    }
}
